#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define inn read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template <typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 5e5+10;

int nodenum = 1,n,k,ch[N<<5][2],siz[N<<5];
ll a[N],t[N],ans;

struct node{int num,rk;ll val;node(int _x,int _y,ll _z):num(_x),rk(_y),val(_z){}};
bool operator < (node x,node y){return x.val < y.val;}

priority_queue<node> q;

void insert(ll x){
	int p = 1;siz[p]++;
	for(int i = 33;i >= 0;i--){
		ll bit = x >> i & 1ll;
		if(!ch[p][bit]) ch[p][bit] = ++nodenum;
		siz[ch[p][bit]]++; p = ch[p][bit];
	}
}

ll query(ll x,int rk){
	int p = 1;ll ans = 0;
	for(int i = 33;i >= 0;i--){
		ll bit = x >> i & 1ll;
		if(siz[ch[p][bit]] >= rk) p = ch[p][bit];
		else rk -= siz[ch[p][bit]],p = ch[p][bit^1],ans |= 1ll << i;
	}
	return ans;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in;
	for(int i = 1;i <= n;i++) a[i] = inn,t[i] = t[i-1] ^ a[i];
	for(int i = 0;i <= n;i++) insert(t[i]);
	for(int i = 0;i <= n;i++) q.push(node(i,n+1,query(t[i],n+1)));
	for(int i = 0;i < k*2;i++){
		node x = q.top(); q.pop();
		ans += x.val; if(x.rk) q.push(node(x.num,x.rk-1,query(t[x.num],x.rk-1)));
	}
	printf("%lld\n",ans>>1);
	return 0;
}
